Skip to content

fix(@angular/build): pass an explicit port of 0 through to the dev server - #34686

Merged
clydin merged 1 commit into
angular:mainfrom
MeAkib:fix/dev-server-port-zero
Nov 11, 2026
Merged

clydin merged 1 commit into
angular:mainfrom
MeAkib:fix/dev-server-port-zero

Conversation

@MeAkib

@MeAkib MeAkib commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

Previously, requesting an ephemeral port (--port 0) was resolved by binding a throwaway net.Server to learn the real port before handing that concrete number to Vite or webpack-dev-server, which then bound it again. This avoided a Vite bug where server.port: 0 was ignored and the default port (5173) was used instead.

That bug is fixed upstream (vitejs/vite#7529, vitejs/vite#23158), and webpack-dev-server has always bound port 0 correctly via Node's own http.Server. Pass 0 straight through instead of pre-resolving it, removing the redundant double-bind.

Verified via the existing port_spec.ts "random free port" test for both the Vite-based and webpack-based dev server, which covers this exact scenario.

@google-cla

google-cla Bot commented Nov 11, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request re-enables the handling of port 0 in the checkPort utility function, allowing the request of an OS-assigned ephemeral port now that Vite correctly supports it. I have no feedback to provide as there are no review comments.

…rver

Previously, requesting an ephemeral port (`--port 0`) was resolved by
binding a throwaway net.Server to learn the real port before handing
that concrete number to Vite or webpack-dev-server, which then bound
it again. This avoided a Vite bug where `server.port: 0` was ignored
and the default port (5173) was used instead.

That bug is fixed upstream (vitejs/vite#7529, vitejs/vite#23158), and
webpack-dev-server has always bound port 0 correctly via Node's own
http.Server. Pass 0 straight through instead of pre-resolving it,
removing the redundant double-bind.

Verified via the existing port_spec.ts "random free port" test for
both the Vite-based and webpack-based dev server, which covers this
exact scenario.
@MeAkib
MeAkib force-pushed the fix/dev-server-port-zero branch from 5b3d233 to 4b29a1b Compare November 11, 2026 14:20
@alan-agius4 alan-agius4 added target: patch This PR is targeted for the next patch release action: merge The PR is ready for merge by the caretaker labels Nov 11, 2026

@alan-agius4 alan-agius4 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@clydin
clydin merged commit 3123cf2 into angular:main Nov 11, 2026
41 checks passed
@clydin

clydin commented Nov 11, 2026

Copy link
Copy Markdown
Member

This PR was merged into the repository. The changes were merged into the following branches:

@MeAkib
MeAkib deleted the fix/dev-server-port-zero branch November 11, 2026 19:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: merge The PR is ready for merge by the caretaker area: @angular/build target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants